#include "../include/head.h"

int initTcp(char *ip,char *port)
{
    int socketfd = socket(AF_INET, SOCK_STREAM, 0);
    
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(port));
    addr.sin_addr.s_addr = inet_addr(ip);

    int flag = 1;
    setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
    int bind_ret = bind(socketfd, (struct sockaddr *)&addr, sizeof(addr));
    ERROR_CHECK(bind_ret, -1, "bind");

    listen(socketfd, 50);

    return socketfd;
}
